package io.plus.user_interface.io.server.command.command_handler;

import io.plus.interactive.AsynchronousSocketChannelContext;
import io.plus.user_interface.io.common.packet.Command;
import io.plus.user_interface.io.common.packet.HeartbeatRequestMessage;
import io.plus.user_interface.io.common.packet.ResponseMessage;
import io.plus.user_interface.io.common.protocol.PacketImpl;
import io.plus.user_interface.io.common.protocol.ProtocolConstants;
import io.plus.user_interface.io.common.utils.ImKit;
import io.plus.user_interface.io.server.command.AbstractCommandHandler;

public class HeartbeatReqHandler extends AbstractCommandHandler {
    @Override
    public Command command() {
        return Command.heartbeat_request;
    }

    @Override
    public PacketImpl handler(PacketImpl packet, AsynchronousSocketChannelContext asynchronousSocketChannelContext) throws Exception {
        ResponseMessage heartbeatBody = new ResponseMessage(Command.heartbeat_request).setData(new HeartbeatRequestMessage(ProtocolConstants.HEARTBEAT_BYTE));
        PacketImpl heartbeatPacket = ImKit.convertResponsepPacket(heartbeatBody, asynchronousSocketChannelContext);
        return heartbeatPacket;
    }
}
